<?php

/**
 * This is the model class for table "customer_resident".
 *
 * The followings are the available columns in table 'customer_resident':
 * @property integer $id
 * @property string $sm_storename
 * @property string $sm_storetype
 * @property string $sm_storemanager
 * @property string $sm_telnum
 * @property string $sm_mallbranch
 * @property string $contact_name
 * @property string $contact_address
 * @property string $contact_telnum
 * @property string $contact_email
 */
class CustomerResident extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'customer_resident';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('sm_storename, sm_storetype, sm_storemanager, contact_main, contact_maintel, sm_mallbranch', 'required'),
			array('sm_telnum, contact_maintel, contact_telnum', 'numerical', 'integerOnly'=>true ),

array('sm_telnum, contact_maintel, contact_telnum', 'length', 'max'=>13),



			array('sm_storename, sm_storetype, sm_storemanager, sm_mallbranch, contact_name, contact_email', 'length', 'max'=>45),
			array('contact_address', 'length','max'=>80),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, sm_storename, sm_storetype, sm_storemanager, sm_telnum, sm_mallbranch, contact_main, contact_maintel,
			contact_address, contact_email, contact_name, contact_telnum ', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
	'tickets' => array(self::HAS_MANY, 'Ticket', 'customer_resident_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'sm_storename' => 'Store Name',
			'sm_storetype' => 'Store Type',
			'sm_storemanager' => 'Store Manager',
			'sm_telnum' => 'Telephone Number',
			'sm_mallbranch' => 'SM Mall Branch',
			'contact_main' => 'Contact Name 1',
			'contact_address' => 'Address',
			'contact_maintel' => 'Telephone Number',
			'contact_name' => 'Contact Name 2',
			'contact_email' => 'Email',
			'contact_telnum' => 'Telephone Number',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('sm_storename',$this->sm_storename,true);
		$criteria->compare('sm_storetype',$this->sm_storetype,true);
		$criteria->compare('sm_storemanager',$this->sm_storemanager,true);
		$criteria->compare('sm_telnum',$this->sm_telnum);
		$criteria->compare('sm_mallbranch',$this->sm_mallbranch,true);
		$criteria->compare('contact_main',$this->contact_main,true);
		$criteria->compare('contact_maintel',$this->contact_maintel,true);
		$criteria->compare('contact_name',$this->contact_name,true);
		$criteria->compare('contact_address',$this->contact_address,true);
		$criteria->compare('contact_telnum',$this->contact_telnum);
		$criteria->compare('contact_email',$this->contact_email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return CustomerResident the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
		}
	
		public function getFullNameResident(){
			return $this->sm_storename." ".$this->sm_mallbranch;
		}
	

}
